package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.UserProduct;
import com.xry.mapper.UserProductDao;
import com.xry.service.UserProductService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserProductServiceImpl implements UserProductService {
    @Autowired
    UserProductDao userProductDao;
    @Override
    @LogMethod(serviceName = "增加产品信息")
    public UserProduct add(UserProduct userProduct) {
        //新增数据
        userProductDao.add(userProduct);
        //通过主键查询数据库中的数据
        UserProduct result = userProductDao.one(userProduct.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "删除产品信息")
    public int del(Integer id) {
        return userProductDao.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改产品信息")
    public UserProduct edit(UserProduct userProduct) {
        userProductDao.edit(userProduct);
        UserProduct result=userProductDao.one(userProduct.getId());
        return result;
    }

    @Override
    public List<UserProduct> all(UserProduct userProduct) {
        return userProductDao.all( userProduct);
    }

    @Override
    public UserProduct one(Integer id) {
        return userProductDao.one(id);
    }

    @Override
    public void page(Page page, UserProduct userProduct){
        int count=userProductDao.pageCount(userProduct);
        Object data=userProductDao.page(page,userProduct);
        page.setCount(count);
        page.setData(data);
    }
}
